using UniversalAdmin.Domain.Common;

namespace UniversalAdmin.Domain.Entities
{
    /// <summary>
    /// 刷新令牌实体
    /// </summary>
    public class RefreshToken : EntityBase
    {
        /// <summary>
        /// 令牌值
        /// </summary>
        public string Token { get; set; } = string.Empty;

        /// <summary>
        /// 用户ID
        /// </summary>
        public int UserId { get; set; }

        /// <summary>
        /// 过期时间
        /// </summary>
        public DateTime ExpiresAt { get; set; }

        /// <summary>
        /// 是否已被撤销
        /// </summary>
        public bool IsRevoked { get; set; } = false;

        /// <summary>
        /// 撤销时间
        /// </summary>
        public DateTime? RevokedAt { get; set; }

        /// <summary>
        /// IP地址
        /// </summary>
        public string? IpAddress { get; set; }

        /// <summary>
        /// 用户代理
        /// </summary>
        public string? UserAgent { get; set; }

        /// <summary>
        /// 关联的用户
        /// </summary>
        public virtual User User { get; set; } = null!;

        /// <summary>
        /// 检查令牌是否有效
        /// </summary>
        public bool IsValid => !IsRevoked && ExpiresAt > DateTime.UtcNow;
    }
}
